//
//  MLMainViewController.swift
//  Weibo
//
//  Created by 李亮亮 on 16/4/6.
//  Copyright © 2016年 Big Fish. All rights reserved.
//

import UIKit

class MLMainViewController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        let mainTabBar = MLMainTabBar()
        setValue(mainTabBar, forKey: "tabBar")
        mainTabBar.plusBtn.addTarget(self, action: #selector(MLMainViewController.plusBtnDidClick), forControlEvents: .TouchUpInside)
        
        addChildViewControllers()
    }
    
    @objc private func plusBtnDidClick() {
        print("WTF")
    }
    
    private func addChildViewControllers() {
     
        addChildViewController(MLHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MLMessageTableViewController(), title: "信息", imageName: "tabbar_message_center")
        addChildViewController(MLDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(MLProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    private func addChildViewController(vc: UIViewController, title: String, imageName: String) {
        
        let nav = UINavigationController(rootViewController: vc)
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        // imageWithRenderingMode 让选中状态的时候显示的不是初始蓝色
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        
        addChildViewController(nav)
    }
    
}
